package com.ymttest.database.sqlwapper.shenqisettlement;

import java.util.HashMap;
import java.util.List;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.shenqisettlement.ProxyFissionSettlementDetail;

public class ProxyFissionSettlementDetailWrapper {

	SqlManager manager;

	public ProxyFissionSettlementDetailWrapper() {
		manager = new SqlManager("shenqisettlement");
	}

	@SuppressWarnings("unchecked")
	public ProxyFissionSettlementDetail selectByPrimaryKey(long id) {

		ProxyFissionSettlementDetail proxyFissionSettlementDetail = new ProxyFissionSettlementDetail();
		List<ProxyFissionSettlementDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.ProxyFissionSettlementDetailMapper.selectByPrimaryKey",
						id);
		manager.commit();

		if (result.size() > 0) {
			proxyFissionSettlementDetail = result.get(0);
		}

		return proxyFissionSettlementDetail;
	}
	
	@SuppressWarnings("unchecked")
	public List<ProxyFissionSettlementDetail> selectByOrderId(long orderId) {

		List<ProxyFissionSettlementDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.ProxyFissionSettlementDetailMapper.selectByOrderId",
						orderId);
		manager.commit();

		return result;
	}
	
	@SuppressWarnings("unchecked")
	public ProxyFissionSettlementDetail selectByOrderIdAndProxyId(Long orderId, Long proxyId) {

		HashMap<String, Long> map = new HashMap<>();
		
		map.put("order_id", orderId);
		map.put("proxy_id", proxyId);
		
		ProxyFissionSettlementDetail proxyFissionSettlementDetail = new ProxyFissionSettlementDetail();
		List<ProxyFissionSettlementDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.ProxyFissionSettlementDetailMapper.selectByOrderIdAndProxyId",
						map);
		manager.commit();

		if (result.size() > 0) {
			proxyFissionSettlementDetail = result.get(0);
		}

		return proxyFissionSettlementDetail;
	}
	
	@SuppressWarnings("unchecked")
	public ProxyFissionSettlementDetail selectByOrderIdAndProxyIdAndBizId(
			Long orderId, Long proxyId, String bizId, int settlementType) {

		HashMap<String, Object> map = new HashMap<>();

		map.put("order_id", orderId);
		map.put("proxy_id", proxyId);
		map.put("biz_id", bizId);
		map.put("proxy_settlement_type", settlementType);

		ProxyFissionSettlementDetail proxyFissionSettlementDetail = new ProxyFissionSettlementDetail();
		List<ProxyFissionSettlementDetail> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.ProxyFissionSettlementDetailMapper.selectByOrderIdAndProxyIdAndBizId",
						map);
		manager.commit();

		if (result.size() > 0) {
			proxyFissionSettlementDetail = result.get(0);
		}

		return proxyFissionSettlementDetail;
	}

	@SuppressWarnings("unchecked")
	public int updateShengpaySharingExecuteStatusByOrderId(
			Long orderId, int shengpaySharingExecuteStatus, int settlementType) {

		HashMap<String, Object> map = new HashMap<>();

		map.put("order_id", orderId);
		map.put("shengpay_sharing_execute_status", shengpaySharingExecuteStatus);
		map.put("proxy_settlement_type", settlementType);

		ProxyFissionSettlementDetail proxyFissionSettlementDetail = new ProxyFissionSettlementDetail();
		int result = manager
				.update("com.ymttest.database.mapping.shenqisettlement.ProxyFissionSettlementDetailMapper.updateShengpaySharingExecuteStatusByOrderId",
						map);
		manager.commit();

		if (result == 0) {
			Logger.comment("没有数据更新");
		}

		return result;
	}
	
	public static void main(String[] args) {
		
		ProxyFissionSettlementDetailWrapper wrapper = new ProxyFissionSettlementDetailWrapper();
		
		System.out.println(wrapper.updateShengpaySharingExecuteStatusByOrderId(14331900338L, 1, 0));
	}
}
